/**
 * @param {string} s
 * @param {string} target
 * @return {number}
 */
var rearrangeCharacters = function(s, target) {
  let targetAlphaArr = new Array(26).fill(0), sAlphaArr = new Array(26).fill(0);
  for(let i = 0; i < target.length; i++) {
    // console.log(target[i].charCodeAt() - 'a'.charCodeAt());
    targetAlphaArr[target[i].charCodeAt() - 'a'.charCodeAt()]++;
  }
  for(let i = 0; i < s.length; i++) {
    // console.log(target[i].charCodeAt() - 'a'.charCodeAt());
    sAlphaArr[s[i].charCodeAt() - 'a'.charCodeAt()]++;
  }
  let count = 0;
  for(let i = 0; i < Math.floor(s.length / target.length); i++) {
    for(let k = 0; k < 26; k++) {
      sAlphaArr[k] -= targetAlphaArr[k];
      if(sAlphaArr[k] < 0) {
        return count;
      }
    }
    count++;
  }
  return count;
};

let s = "ilovecodingonleetcode", target = "code";
console.log(rearrangeCharacters(s, target));
s = "abcba", target = "abc";
console.log(rearrangeCharacters(s, target));
s = "abbaccaddaeea", target = "aaaaa";
console.log(rearrangeCharacters(s, target));
